package com.shangma.controller;

import com.shangma.entity.User;
import com.shangma.utils.AsyncFactory;
import com.shangma.utils.AsyncManager;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("common")
public class TestController {
    @Autowired
    private AsyncManager asyncManager;

    @GetMapping("doLogin/{phone}/{code}")
    public String doLogin(@PathVariable String phone,@PathVariable String code){
        System.out.println(phone + code);
        return "success";
    }

    @PostMapping("regist")
    public String regist(@RequestBody User user){
        System.out.println(user);
        // 添加数据
        return "success";
    }

    @PutMapping("update")
    public String update(@RequestBody User user){
        System.out.println(user);
        // 可以修改数据
        return "success";
    }

    @DeleteMapping("delete/{keys}")
    public String delete(@PathVariable String keys){
        System.out.println(keys);
        String[] split = keys.split(",");
        List<String> strings = Arrays.asList(split);
        strings.forEach(str->{
            Integer integer = Integer.valueOf(str);
            System.out.println(integer);
        });
        return "success";
    }

    @GetMapping("sendCode")
    public String sendCode(){
        String phone = "18500610302";
        String code = "123456";
        asyncManager.execute(AsyncFactory.sendValicode(phone,code));
        System.out.println("继续执行了");
        return "success";
    }
}
